
package com.phm.phmneuron.gng;

import com.phm.phmneuron.neuron.Neuron;

/**
 *
 * @author PARHAM
 */
public class GNGNeuron extends Neuron implements Comparable<GNGNeuron>, Cloneable {
    public static final int NEURON_DISTANCE_KEY = 0x0101;
    public static final int NEURON_DIS_DIMENSION_KEY = 0x0102;
    public static final int NEURON_LOCALERROR_KEY = 0x0103;
    
    public GNGNeuron () {
        this (DEFAULT_DIMENSION);
    }
    public GNGNeuron (int dim) {
        super (dim);
        parameters.updateParameter(NEURON_DISTANCE_KEY, 0.0f);
        parameters.updateParameter(NEURON_DIS_DIMENSION_KEY, new float [getDimension()]);
        parameters.updateParameter(NEURON_LOCALERROR_KEY, 0.0f);
    }
    public GNGNeuron (float [] center) {
        this (center.length);
        setCentroid(center);
    }
    
    public void setDistance (float dis) {
        parameters.updateParameter(NEURON_DISTANCE_KEY, dis);
    }
    public float getDistance () {
        return (Float) parameters.getParameter (NEURON_DISTANCE_KEY);
    }
    public void setLocalError (float error) {
        parameters.updateParameter(NEURON_LOCALERROR_KEY, error);
    }
    public float getLocalError () {
        return (Float) parameters.getParameter (NEURON_LOCALERROR_KEY);
    }
    public void setDistanceDimension (float [] dims) {
        parameters.updateParameter(NEURON_DIS_DIMENSION_KEY, dims);
    }
    public float [] getDistanceDimension () {
        return (float []) parameters.getParameter (NEURON_DIS_DIMENSION_KEY);
    }
    
    @Override
    public int compareTo(GNGNeuron t) {
        float dis1 = (Float) parameters.getParameter(NEURON_DISTANCE_KEY);
        float dis2 = (Float) t.parameters.getParameter(NEURON_DISTANCE_KEY);
        float temp = dis1 - dis2;
        if (temp == 0) {
            return 0;
        } else if (temp > 0) {
            return 1;
        } else {
            return -1;
        }
    }
}
